/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jeelabs.lab2;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author mariusz.gomse
 */
@Entity
@Table(name = "DRAGON")
@NamedQueries({
    @NamedQuery(name = "Dragon.findAll", query = "SELECT d FROM Dragon d"),
    @NamedQuery(name = "Dragon.findById", query = "SELECT d FROM Dragon d WHERE d.id = :id"),
    @NamedQuery(name = "Dragon.findByNickname", query = "SELECT d FROM Dragon d WHERE d.nickname = :nickname"),
    @NamedQuery(name = "Dragon.findByWingspan", query = "SELECT d FROM Dragon d WHERE d.wingspan = :wingspan"),
    @NamedQuery(name = "Dragon.findByFireColor", query = "SELECT d FROM Dragon d WHERE d.fireColor = :fireColor")})
public class Dragon implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 128)
    @Column(name = "NICKNAME")
    private String nickname;
    @Column(name = "WINGSPAN")
    private Integer wingspan;
    @Size(max = 64)
    @Column(name = "FIRE_COLOR")
    private String fireColor;
    @JoinColumn(name = "CAVE", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private Cave cave;

    public Dragon() {
    }

    public Dragon(Integer id) {
        this.id = id;
    }

    public Dragon(Integer id, String nickname) {
        this.id = id;
        this.nickname = nickname;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public Integer getWingspan() {
        return (wingspan == null) ? -1 : wingspan;
    }

    public void setWingspan(Integer wingspan) {
        this.wingspan = wingspan;
    }

    public String getFireColor() {
        return (fireColor == null) ? "-----" : fireColor;
    }

    public void setFireColor(String fireColor) {
        this.fireColor = fireColor;
    }

    public Cave getCave() {
        return cave;
    }

    public void setCave(Cave cave) {
        this.cave = cave;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Dragon)) {
            return false;
        }
        Dragon other = (Dragon) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "jeelabs.lab2.Dragon[ id=" + id + " ]";
    }
    
}
